home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "Set Menu Caption"
- ClientHeight = 1860
- ClientLeft = 1320
- ClientTop = 2010
- ClientWidth = 5205
- Height = 2550
- Left = 1260
- LinkTopic = "Form1"
- ScaleHeight = 1860
- ScaleWidth = 5205
- Top = 1380
- Width = 5325
- Begin MsgHook MsgHook
- Left = 120
- Top = 120
- End
- Begin TextBox Text1
- Height = 285
- Left = 120
- TabIndex = 0
- Text = "Enter text here and open File menu"
- Top = 720
- Width = 4935
- End
- Begin Menu mnuFile
- Caption = "&File"
- Begin Menu mnuFileText
- Caption = "<<>>"
- End
- Begin Menu mnuFileSep10
- Caption = "-"
- End
- Begin Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Option Explicit
- ' Windows contant
- Const WM_INITMENUPOPUP = &H117
- Sub Form_Load ()
- ' Setup MsgHook
- MsgHook.HwndHook = Me.hWnd
- MsgHook.Message(WM_INITMENUPOPUP) = True
- End Sub
- Sub mnuFileExit_Click ()
- Unload Me
- End Sub
- Sub mnuFileText_Click ()
- Dim msg As String
- msg = "This program shows how to change the text of"
- msg = msg & " a menu item at run-time. Note that you"
- msg = msg & " can do this with straight VB in response"
- msg = msg & " to the mnuFile_Click event. However,"
- msg = msg & " doing it this way, the text will get cut"
- msg = msg & " off if it is longer than the currently"
- msg = msg & " longest menu item." & Chr$(13) & Chr$(10)
- msg = msg & Chr$(13) & Chr$(10)
- msg = msg & "Trapping WM_INITPOPUPMENU lets you set"
- msg = msg & " menu text before Windows determines the"
- msg = msg & " width of the menu."
- MsgBox msg
- End Sub
- Sub MsgHook_Message (msg As Integer, wParam As Integer, lParam As Long, result As Long)
- If msg = WM_INITMENUPOPUP Then
- ' Update menu text if index = 0 (File menu)
- If (lParam And &HFFFF&) = 0 Then
- mnuFileText.Caption = Text1
- result = 0
- End If
- End If
- End Sub
-